/*    */ package com.zimbra.cs.service.admin;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.AdminConstants;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.Domain;
/*    */ import com.zimbra.cs.account.NamedEntry;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.account.SearchAccountsOptions;
/*    */ import com.zimbra.cs.account.SearchAccountsOptions.IncludeType;
/*    */ import com.zimbra.cs.account.SearchDirectoryOptions.MakeObjectOpt;
/*    */ import com.zimbra.cs.account.accesscontrol.AccessControlUtil;
/*    */ import com.zimbra.cs.mailbox.MailboxManager;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.HashMap;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class GetAggregateQuotaUsageOnServer
/*    */   extends AdminDocumentHandler
/*    */ {
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 40 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 41 */     if (!AccessControlUtil.isGlobalAdmin(getAuthenticatedAccount(zsc))) {
/* 42 */       throw ServiceException.PERM_DENIED("only global admin is allowed");
/*    */     }
/*    */     
/* 45 */     Map<String, Long> domainAggrQuotaUsed = new HashMap();
/*    */     
/* 47 */     SearchAccountsOptions searchOpts = new SearchAccountsOptions();
/* 48 */     searchOpts.setIncludeType(SearchAccountsOptions.IncludeType.ACCOUNTS_ONLY);
/* 49 */     searchOpts.setMakeObjectOpt(SearchDirectoryOptions.MakeObjectOpt.NO_DEFAULTS);
/*    */     
/* 51 */     Provisioning prov = Provisioning.getInstance();
/* 52 */     List<NamedEntry> accounts = prov.searchAccountsOnServer(prov.getLocalServer(), searchOpts);
/* 53 */     Map<String, Long> acctQuotaUsed = MailboxManager.getInstance().getMailboxSizes(accounts);
/* 54 */     for (NamedEntry ne : accounts)
/* 55 */       if ((ne instanceof Account))
/*    */       {
/*    */ 
/* 58 */         Account acct = (Account)ne;
/* 59 */         Long acctQuota = (Long)acctQuotaUsed.get(acct.getId());
/* 60 */         if (acctQuota == null) {
/* 61 */           acctQuota = Long.valueOf(0L);
/*    */         }
/* 63 */         String domainId = acct.getDomainId();
/* 64 */         if (domainId != null)
/*    */         {
/*    */ 
/* 67 */           Long aggrQuota = (Long)domainAggrQuotaUsed.get(domainId);
/* 68 */           domainAggrQuotaUsed.put(domainId, Long.valueOf(aggrQuota == null ? acctQuota.longValue() : aggrQuota.longValue() + acctQuota.longValue()));
/*    */         }
/*    */       }
/* 71 */     Element response = zsc.createElement(AdminConstants.GET_AGGR_QUOTA_USAGE_ON_SERVER_RESPONSE);
/* 72 */     for (String domainId : domainAggrQuotaUsed.keySet()) {
/* 73 */       Domain domain = prov.getDomainById(domainId);
/* 74 */       Element domainElt = response.addElement("domain");
/* 75 */       domainElt.addAttribute("name", domain.getName());
/* 76 */       domainElt.addAttribute("id", domainId);
/* 77 */       domainElt.addAttribute("used", (Number)domainAggrQuotaUsed.get(domainId));
/*    */     }
/* 79 */     return response;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/GetAggregateQuotaUsageOnServer.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */